<?php require_once '../funciones/funciones.php'; ?>
<!--
Descripcion: Archivo para crear todos los distractores de una pregunta, asi esta sea teórica o práctica.
-->
<!DOCTYPE html>
<html>
    <head>
        <?php require_once '../includes/head.html' ?>
<!--        <script type="text/javascript" src="../js/tiny_mce/tiny_mce_gzip.js"></script>-->
        <script type="text/javascript" src="../js/tiny_mce/tiny_mce.js"></script>
        <title>Distractores para Preguntas Teorícas</title>
        <script type="text/javascript">
            jQuery(document).ready(function(){
<?php require_once '../includes/jsEnReady.php'; ?>
        jQuery("#list").jqGrid({
            url: '../scripts/cargaDistractores.php?tran=<?php echo $_REQUEST['transaccion']; ?>',
            datatype: 'xml',
            colNames:['Orden','Clave','Distractor'],
            colModel :[
                {name:'tempInt2',index:'tempInt2', width:60, editable:true},
                {name:'tempInt3',index:'tempInt3', width:60, editable:true,edittype:"select",editoptions:{value:"0:No;1:Si"}},
                {name:'tempText1',index:'tempText1', width:200, editable:true}
            ],
            editurl: "editaDistractores.php",
            ondblClickRow: function(id){asignaValores(id);},
            autowidth: true,
            pager: jQuery('#pager'),
            rowNum:50,
            rowList:[10,20,30,50],
            sortname: 'tempInt2',
            sortorder: "asc",
            viewrecords: true,
            caption: 'Distractores',
            height:260
        });


        //Barra de navegación
        jQuery("#list").navGrid('#pager',{
            edit:false,
            add:false,
            del:true,
            search:false,
            view:true
        });
                
        $("#btnGuardar").click(function(){
            if($("#orden").val() <= 0 || $("#orden").val() == "" || isNaN($("#orden").val())){
                mensajes("Debe ingresar un número de Orden valido", 1, false);
                $("#orden").focus();
                return false;
            }
            if(tinyMCE.get('des').getContent() == ""){
                mensajes("Debe ingresar un distractor valido", 1, false);
                $("#des").focus();
                return false;
            }
            $("#des").val(tinyMCE.get('des').getContent());
            $.post("../scripts/guardaTemporal.php",$("#formDistractor").serialize(),function(data){
                if(parseInt(data) == 1){
                    inicaFormulario();
                    return true;
                }
                else{
                    mensajes(data, 0, false);
                    return false;
                }
            });
        }); //fin $("#btnGuardar").click(function(){
        
        $("#btnCancelar").click(function(){
            inicaFormulario();
        });
    }); // fin jQuery(document).ready(function(){
            
    function asignaValores(id){
        $.getJSON("../scripts/cargasJson.php",{opc:'1',val:id},function(datos){
            inicaFormulario();
            $("#orden").val(datos.tempInt2);
            $("#clave").val(datos.tempInt3);
            tinyMCE.execCommand('mceInsertContent',false,datos.tempText1);
            $("#des").val(datos.tempText1);
            $("#tempId").val(datos.tempId);
            $("#accion").val('E');
        });
    }
    function inicaFormulario(){
        $("#formDistractor").trigger("reset");
        $("#transaccion").val('<?php echo $_REQUEST['transaccion']; ?>');
        $("#opc").val('1');
        $('#list').trigger('reloadGrid');
        $("#accion").val('C');
        return true;
    }
        </script>
        <script type="text/javascript">
            tinyMCE_GZ.init({
                <!-- user-defined plugins and themes should be identical to those in "tinyMCE.init" below.-->
                plugins : 'style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,'+
                    'searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras',
                languages : 'es',
                themes : 'simple,advanced',
                disk_cache : true,
                debug : false
            });
        </script>
        <script type="text/javascript">
            tinyMCE.init({
                // General options
                mode : "textareas",
                language : 'es',
                theme : "advanced",

                plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

                // Theme options
                theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2 : "pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,|,ltr,rtl",
                theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_statusbar_location : "bottom",
                theme_advanced_resizing : true,

                // Example content CSS (should be your site CSS)
                content_css : "css/content.css",

                // Drop lists for link/image/media/template dialogs
                template_external_list_url : "lists/template_list.js",
                external_link_list_url : "lists/link_list.js",
                external_image_list_url : "lists/image_list.js",
                media_external_list_url : "lists/media_list.js",

                // Style formats
                style_formats : [
                    {title : 'Bold text', inline : 'b'},
                    {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
                    {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
                    {title : 'Example 1', inline : 'span', classes : 'example1'},
                    {title : 'Example 2', inline : 'span', classes : 'example2'},
                    {title : 'Table styles'},
                    {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
                ],

                // Replace values for the template plugin
                template_replace_values : {
                    username : "Some User",
                    staffid : "991234"
                }
            });
        </script>
    </head>
    <body>
        <div class="ui-accordion-header ui-state-default ui-corner-all titulo">INGRESE TODOS LOS DISTRACTORES</div>
        <?php include '../includes/body.php'; ?>
        <div style="float: right;">
            <a href="ayudaAdmin.php#distractorTeorico" title="Ayuda" target="_new"><img src="../imagenes/ayuda1.png" alt="Ayuda" title="Ayuda" /></a>
        </div>
        <form id="formDistractor" method="POST" >
            <input type="hidden" name="accion" id="accion" value="C" />
            <input type="hidden" name="tempId" id="tempId" />
            <input type="hidden" name="opc" id="opc" value="1" />
            <input type="hidden" name="transaccion" id="transaccion" value="<?php echo $_REQUEST['transaccion']; ?>" />
            <div style="float: left;margin-right: 15px">
                <table style="border-right: 7px">
                    <tr>
                        <td><label for="orden">Orden</label></td>
                        <td><input type="text" name="orden" id="orden" size="4" /></td>
                        <td><label for="clave" title="Indica si el distractor es la respuesta correcta">Clave</label></td>
                        <td><select name="clave" id="clave">
                                <option value="0">No</option>
                                <option value="1">Si</option>
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="text-align: center">
                <input type="button"  style="padding: 2px 2px;" value="Guardar Distractor" id="btnGuardar" /><input type="button" value="Cancelar" id="btnCancelar" style="padding: 2px 2px;" /><input type="button" value="Terminar Ingreso" id="btnTerminar" onclick="window.close()" style="padding: 2px 2px;" />
            </div>
            <div style="margin: 16px 0px 0px 0px">
                <span style="font-size: 14px;font-weight: 900">A CONTINUACIÓN INGRESE EL CONTENIDO DEL DISTRACTOR</span>
                <textarea name="des" id="des" style="width: 100%" rows="2"></textarea>
            </div>
        </form>
        <h3 style="color: red">Doble click sobre el distractor para editar</h3>
        <div id="pager" class="scroll" style="text-align:center;"></div>
        <table id="list" class="scroll"></table>

    </body>
</html>
